package com.thams.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.support.WebApplicationContextUtils;

import com.thams.entity.Customer;
import com.thams.service.i.IU8Service;
import com.thams.util.MessagePrinter;

public class CustomerServlet extends HttpServlet {

	private static IU8Service service;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		service = (IU8Service) WebApplicationContextUtils
		.getRequiredWebApplicationContext(
				request.getSession().getServletContext()).getBean(
				"u8Service");
		List<Customer> ul = service.getCustomerList();
		StringBuilder sb = new StringBuilder("[");
		for (int i = 0; i < ul.size(); i++) {
			Customer cs = ul.get(i);
			sb.append(cs.toJSON());
			if (i != ul.size() - 1) {
				sb.append(",");
			}
		}
		sb.append("]");
		MessagePrinter.printObject(sb.toString(),request, response);
	}

}
